<?php

namespace App\Admin\Controllers;

use App\Models\Order;
use App\Models\OrderTip;
use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrderTipsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '订单提醒';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new OrderTip);

        $grid->column('id', __('Id'));
        $grid->column('order_id', __('订单号'))
            ->display(function($order_id){
            $order = Order::find($order_id);
            if ($order) {
                $order = $order['no'];
            }
            return $order;
        });
        $grid->column('user_id', __('用户'))
            ->display(function($user_id){
            $user = User::find($user_id);
            if($user){
                $user = $user['mobile'];
            }
            return $this->created_at.'收到用户'.$user.'订单提醒';
        });
        $grid->column('tip_status', __('处理状态'))
            ->editable('select',[0=>'未处理',1=>'已处理']);
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(OrderTip::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('order_id', __('Order id'));
        $show->field('user_id', __('User id'));
        $show->field('tip_status', __('Tip status'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new OrderTip);

        $form->number('order_id', __('Order id'));
        $form->number('user_id', __('User id'));
        $form->switch('tip_status', __('Tip status'));

        return $form;
    }
}
